package com.cal.utms.entity;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.cal.utms.logAudit.AuditLogInt;
import com.cal.utms.util.ValueConvert;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the customer_redemption_request database table.
 * 
 */
@Entity
@Table(name = "customer_redemption_request")
@NamedQuery(name = "CustomerRedemptionRequest.findAll", query = "SELECT c FROM CustomerRedemptionRequest c")
public class CustomerRedemptionRequest implements Serializable, AuditLogInt {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Temporal(TemporalType.DATE)
	@Column(name = "CONFIRM_DATE")
	private Date confirmDate;

	@Temporal(TemporalType.DATE)
	@Column(name = "EXPECTED_DATE")
	private Date expectedDate;

	@Column(name = "REDEMPTION_CODE")
	private String redemptionCode;

	@Column(name = "REDEMPTION_TYPE")
	private String redemptionType;

	@Temporal(TemporalType.DATE)
	@Column(name = "REQUEST_DATE")
	private Date requestDate;

	@Column(name = "STATUS")
	private String status;

	@Column(name = "TOT_AMOUNT")
	private BigDecimal totAmount;

	@Column(name = "TOT_UNIT")
	private BigDecimal totUnit;

	@ManyToOne
	@JoinColumn(name = "CUSTOMER_ID")
	private Customer customer;

	@Column(name = "REDEM_UNIT_PRICE")
	private BigDecimal redemUnitPrice;

	@ManyToOne
	@JoinColumn(name = "FUND_ID")
	private Fund fund;

	@OneToMany(mappedBy = "customerRedemptionRequest", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<RedemptionReqToRedemtion> redemptionReqToRedemtions;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "RECORD_DATE")
	private Date recordDate;

	@Column(name = "RECORD_USER")
	private int recordUser;

	@Column(name = "CONFIRM_USER")
	private int confirmUser;

	@Column(name = "RECORD_ENTER_TYPE")
	private String recordType;

	public CustomerRedemptionRequest() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getConfirmDate() {
		return this.confirmDate;
	}

	public void setConfirmDate(Date confirmDate) {
		this.confirmDate = confirmDate;
	}

	public Date getExpectedDate() {
		return this.expectedDate;
	}

	public void setExpectedDate(Date expectedDate) {
		this.expectedDate = expectedDate;
	}

	public String getRedemptionCode() {
		return this.redemptionCode;
	}

	public void setRedemptionCode(String redemptionCode) {
		this.redemptionCode = redemptionCode;
	}

	public String getRedemptionType() {
		return this.redemptionType;
	}

	public void setRedemptionType(String redemptionType) {
		this.redemptionType = redemptionType;
	}

	public Date getRequestDate() {
		return this.requestDate;
	}

	public void setRequestDate(Date requestDate) {
		this.requestDate = requestDate;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public BigDecimal getTotAmount() {
		return this.totAmount;
	}

	public void setTotAmount(BigDecimal totAmount) {
		this.totAmount = totAmount;
	}

	public BigDecimal getTotUnit() {
		return this.totUnit;
	}

	public void setTotUnit(BigDecimal totUnit) {
		this.totUnit = totUnit;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Fund getFund() {
		return this.fund;
	}

	public void setFund(Fund fund) {
		this.fund = fund;
	}

	public List<RedemptionReqToRedemtion> getRedemptionReqToRedemtions() {
		return this.redemptionReqToRedemtions;
	}

	public void setRedemptionReqToRedemtions(List<RedemptionReqToRedemtion> redemptionReqToRedemtions) {
		this.redemptionReqToRedemtions = redemptionReqToRedemtions;
	}

	public RedemptionReqToRedemtion addRedemptionReqToRedemtion(RedemptionReqToRedemtion redemptionReqToRedemtion) {
		getRedemptionReqToRedemtions().add(redemptionReqToRedemtion);
		redemptionReqToRedemtion.setCustomerRedemptionRequest(this);

		return redemptionReqToRedemtion;
	}

	public RedemptionReqToRedemtion removeRedemptionReqToRedemtion(RedemptionReqToRedemtion redemptionReqToRedemtion) {
		getRedemptionReqToRedemtions().remove(redemptionReqToRedemtion);
		redemptionReqToRedemtion.setCustomerRedemptionRequest(null);

		return redemptionReqToRedemtion;
	}

	public BigDecimal getRedemUnitPrice() {
		return redemUnitPrice;
	}

	public void setRedemUnitPrice(BigDecimal redemUnitPrice) {
		this.redemUnitPrice = redemUnitPrice;
	}

	public Date getRecordDate() {
		return recordDate;
	}

	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}

	public int getRecordUser() {
		return recordUser;
	}

	public void setRecordUser(int recordUser) {
		this.recordUser = recordUser;
	}

	public int getConfirmUser() {
		return confirmUser;
	}

	public void setConfirmUser(int confirmUser) {
		this.confirmUser = confirmUser;
	}

	public String getRecordType() {
		return recordType;
	}

	public void setRecordType(String recordType) {
		this.recordType = recordType;
	}

	@Transient
	@Override
	public Long getLogId() {
		return ValueConvert.toLong(this.id);
	}

	@Transient
	@Override
	public String getLogDeatil() {
		StringBuilder sb = new StringBuilder();
		sb.append("Redemption Id : ").append(id).append(" Redemption Code : ").append(this.redemptionCode);

		return sb.toString();
	}

}